﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using ProjetoSolo.QueroGas.Aplicacao.ServicosExternos;

namespace ProjetoSolo.QueroGas.Infraestrutura.ServicosWeb
{
    public class ServicoCriptografiaMD5 : IServicoCriptografia
    {
        public string Criptografar(string valor)
        {
            MD5 md5 = MD5.Create();

            byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(valor));
            
            StringBuilder stringCriptografada = new StringBuilder();

            for (int i = 0; i < hash.Length; i++)
            {
                stringCriptografada.Append(hash[i].ToString("X2"));
            }

            return stringCriptografada.ToString();
        }
    }
}
